from page.net_project_page import NetProjectPage
from page.common_tools import CommonTools
from common.page import IOS, XPATH
import random as r
import time as t


today = t.strftime('%Y%m%d', t.localtime(t.time()))


class XinWorkPage(NetProjectPage, CommonTools):
    # 作业发布页面
    year_wheel = (XPATH, "//XCUIElementTypePickerWheel[1]")
    submit_work_btn = (IOS, "type == 'XCUIElementTypeStaticText' AND label == '提交作业'")
    qpl =(IOS,"type == 'XCUIElementTypeStaticText' AND label == '去评论'")
    not_view = (IOS, "type == 'XCUIElementTypeButton' AND label == '未批阅'")
    submint = (XPATH, "//XCUIElementTypeStaticText[contains(@name == '未提交')]")
    zijian = (IOS, 'type==XCUIElementTypeStaticText AND label="请输入自荐理由"')
    def release_work(self, title='%s自动化测试作业%d' % (today, r.randint(100, 999))):
        self.find_button("发布").click()
        self.find_static_text("作业标题").click()
        self.find_static_text("作业标题").send_keys(title)
        self.hide_keyboard()
        self.find_static_text("发布范围").click()
        self.find_button("确认").click()
        self.find_static_text("数学计划").click()
        self.find_button("确认").click()
        self.find_static_text("开始时间").click()
        self.find_button("确定").click()
        self.find_static_text("截止时间").click()
        self.get_frame_center_and_swipe(self.year_wheel)
        self.find_button("确定").click()
        self.find_static_text("输入作业内容").click()
        self.find_static_text("输入作业内容").send_keys("不能设想，古罗马的角斗场需要重建，庞贝古城需要重建，柬埔寨的吴哥窟需要重建。这就像不能设想，远年的古铜器需要抛光，出土的断戟需要镀镍，宋版图书需要上塑，马王堆的汉代老太需要植皮丰胸，重施浓妆。只要历史不阻断，时间不倒退，一切都会衰老。没有皱纹的祖母是可怕的，没有白发的老者是让人遗憾的")
        # self.hide_keyboard()
        self.find_button("完成").click()
        self.find_button("确定").click()
        t.sleep(1)
        self.swipe(210,390,210,390)
        # self.find_xpath('//*[@name="研学通"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeAlert[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[3]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[3]').click()
        t.sleep(3)
        self.swipe(0,135,0,135)
        self.swipe_dr('up')
        self.find_button(string="返回", contains_flag=1).click()
        t.sleep(0.5)
        self.find_button(string="返回",contains_flag=1).click()
        t.sleep(0.5)
        self.find_button(string="common back light icon", contains_flag=1).click()


    def submit_work(self, title='自动化测试作业'):
        self.find_static_text(title, contains_flag=1).click()
        t.sleep(3)
        self.get_frame_center_and_click(self.submit_work_btn)
        # self.swipe(10,695,10,695)
        # self.find_button("未选公开").click()
        # self.find_static_text("点击输入自荐理由").click()
        # t.sleep(2)
        # # self.find_xpath('//*[@name="请输入自荐理由"]').send_keys("这是自荐详细理由，请知悉。。。")
        # self.find_static_text("请输入自荐理由").send_keys("这是自荐理由的详细内容，请知悉。。。。。")
        # self.find_button("保存").click()
        # t.sleep(1)
        self.find_static_text("查看详情").click()
        self.find_button("我同意").click()
        self.find_static_text("请输入作业内容").click()
        self.find_static_text("请输入作业内容").click()
        self.find_static_text("请输入作业内容").send_keys("在这个世界上，有的人信神，有的人不信，由此而区分为有神论者和无神论者、宗教徒和俗人。还有一个比这重要得多的区分，便是有的人相信神圣。往往取决于个人所隶属的民族传统、文化背景和个人的特殊经历，甚至取决于个人的某种神秘体验，这是勉强不得的。")
        self.find_button("保存").click()
        self.find_button('附件').click()
        self.find_button("xiangji").click()
        t.sleep(0.5)
        self.find_xpath('//*[@name="hVideo_take"]').click()  # 拍照
        t.sleep(3)
        self.find_button("完成").click()
        t.sleep(1)
        self.find_button("提交").click()
        t.sleep(3)
        # self.find_static_text(string="去评论",contains_flag=1).click()
        # self.get_frame_center_and_click(self.qpl)
        self.swipe(208,693,208,693)  #点击去评论
        self.find_button("已互评").click()
        self.find_button("未互评").click()
        self.find_button(string="返回", contains_flag=1).click()
        self.swipe_dr('down')
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="common back light icon", contains_flag=1).click()
        t.sleep(2)


    def view_work(self, title='自动化测试作业'):
        self.find_static_text(title, contains_flag=1).click()
        t.sleep(3)
        self.swipe(x1=200, y1=250, x2=200, y2=200)
        self.get_frame_center_and_click(self.not_view)
        t.sleep(8)
        self.find_button("批阅").click()
        self.find_button("优秀").click()
        self.find_static_text("请输入评语...").click()
        self.find_static_text("0").send_keys("自从你生下来的那一刹那起，你就注定要回去。这中间的曲折磨难、顺畅欢乐便是你的命运。不要因为命运的怪诞而俯首听命于它，任凭它的摆布。你一生的全部就在于：运用你手里所拥有的去获取上帝所掌握的。你的努力越超常，你手里掌握的那一半就越庞大，你获得的就越丰硕。在你彻底绝望的时候，别忘了自己拥有一半的命运。这就是命运的一生；这就是一生的命运。")
        self.find_static_text("批阅").click()  # 点击其他位置以收回键盘
        self.find_button("确认").click()
        self.find_button("完成").click()
        t.sleep(2)
        self.find_button(string="返回", contains_flag=1).click()
        self.swipe_dr('down')
        self.find_button(string="提醒", contains_flag=1).click()
        t.sleep(0.5)
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="common back light icon", contains_flag=1).click()
        t.sleep(2)

if __name__ == '__main__':
    test = XinWorkPage()
    # test.login('atgly')
    test.enter_project()
    test.enter_tools('作业')
    # test.release_work()
    # test.logout()
    # test.login('atxy1')
    # test.submit_work()
    test.view_work()
